<template>
	<view class="backgroud">
		<view class="love_story">
			Love Story
		</view>
		<view class="frame">
			<view class="inputtips">
				手机号
			</view>
			<view class="inputframe-r">
				<input type="text" v-model="tel" placeholder="手机号" placeholder-class="co">
			</view>
			<view class="inputtips">
				用户名
			</view>
			<view class="inputframe-r">
				<input type="text" v-model="name" placeholder="用户名" placeholder-class="co">
			</view>
			<view class="inputtips">
				设置密码
			</view>
			<view class="inputframe-r">
				<input type="password" v-model="password" placeholder="设置密码" placeholder-class="co">
			</view>
		</view>
		<view class="tosign" @tap="tosign">
			已有账号？去登录 >>
		</view>
		<view class="registeredbuttonframe" @tap="register()">
			注册
		</view>
	</view>
</template>

<script>
	const phoneReg = /^1[3456789]\d{9}$/;
	export default {
		data() {
			return {
				tel: "",
				name: "",
				password: "",
			}
		},
		methods: {
			tosign() {
				uni.navigateTo({
					url: "/pages/signin/signin"
				})
			},
			register() {
				if (!phoneReg.test(this.tel)) {
					uni.showToast({
						title: '请检查手机号',
						icon: "error",
						duration: 1500
					})
				} else {
					uni.request({
						data: {
							tel: this.tel,
							password: this.password,
							name: this.name
						},
						url: this.$baseUrl + "/user/register",
						method: 'POST',
						success: (res) => {
							if (res.data.data === "used") {
								uni.showToast({
									title: '手机号已被注册',
									icon: "error",
									duration: 1500
								})
							} else {

								uni.showToast({
										title: "注册成功",
										icon: 'success',
										duration: 1500
									}),

									setTimeout(() => {
										uni.navigateTo({
											url: "/pages/signin/signin"
										})
									}, 1500)
							}
						}
					})
				}
			}
		}
	}
</script>

<style>
	.backgroud {
		background: linear-gradient(197.99deg, #2C9AFF -14.52%, #9C74F3 16.96%, #EC81B4 54.17%, #F1BC97 74.34%, #F4E283 100%);
		min-height: 100vh;
		width: 100vw;
		display: flex;
		flex-direction: column;
	}

	.love_story {
		margin-bottom: 100px;
		padding-top: 80px;
		margin-left: 24px;
		font-family: 'PingFang SC';
		font-style: normal;
		font-weight: 500;
		font-size: 36px;
		line-height: 36px;
		/* identical to box height, or 100% */

		color: #FFFFFF;
	}

	.inputframe-r {
		width: auto;
		height: 40px;
		margin-left: 24px;
		margin-right: 24px;
		margin-bottom: 30px;
		padding-top: 16px;
		mix-blend-mode: normal;
		box-sizing: border-box;

		border-bottom: 1px solid #dbdbdb;
		border-top: 0px;
		border-left: 0px;
		border-right: 0px;
		font-family: 'PingFang SC';
		font-style: normal;
		font-size: 18px;
		line-height: 18px;
		/* identical to box height, or 100% */
		color: white;
	}

	.registeredbuttonframe {
		width: auto;
		height: 40px;
		margin-left: 24px;
		margin-right: 24px;
		margin-top: 30px;
		padding-top: 16px;
		background: #FFFFFF;
		opacity: 0.7;
		border-radius: 41px;
		text-align: center;
	}



	.inputtips {
		margin-left: 24px;
		color: white;
		font-family: PingFang SC;
		font-size: 18px;
		font-weight: 500;
		line-height: 18px;
		letter-spacing: 0px;
		text-align: left;
		margin-bottom: 5px;
	}

	.co {
		color: black;
		opacity: 0.5;
	}

	.tosign {
		padding-left: 24px;
		position: relative;
		top: -10px;
		font-family: 'PingFang SC';
		font-style: normal;
		font-size: 18px;
		line-height: 18px;
		/* identical to box height, or 100% */
		color: white;
	}

	.frame {
		position: relative;
	}

	.usedtips {
		position: absolute;
		top: -18%;
		left: 50%;
		transform: translate(-50%, -50%);
		color: darkred
	}
</style>